package com.neusoft.controller;

import com.neusoft.entity.Student;
import com.neusoft.service.StudentService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author: duan
 * @Date: Create in 17:11 2020/10/31
 */
@WebServlet(urlPatterns = {"/student", "/student/queryById", "/student/insert"})
public class StudentController extends BaseController<StudentService> {
//    StudentService studentService;

//    @Override
//    public void init() throws ServletException {
//        System.out.println("init初始化");
//        ApplicationContext app = (ApplicationContext) getServletContext().getAttribute("app");
//        studentService = app.getBean(StudentService.class);
//    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String uri = req.getRequestURI();
        System.out.println(req.getContextPath() + "/student/queryById");
        if (uri.equals(req.getContextPath() + "/student/queryById")) {
            queryById(1);
        } else if (uri.equals(req.getContextPath() + "/student/insert")) {
            insert(null);
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    }

    public void queryById(Integer id) {
        Student student = getServiceBean(StudentService.class).queryById(2);
        System.out.println(student);
    }

    public void insert(Student student) {
        System.out.println("insert");
    }
}
